<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Bootstrap - 简洁、直观、强悍、移动设备优先的前端开发框架，让web开发更迅速、简单。">
    <meta name="author" content="Bootstrap中文网">

    <title>

        美人黛&middot;接口文档

    </title>

    <link href="../dist/css/bootstrap.min.css" rel="stylesheet">


    <!-- Documentation extras -->
    <link href="../dist/css/docs.css" rel="stylesheet">
    <link href="../dist/css/github.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../dist/hl-styles/rainbow.css"/>
    <style>
        body {
            font-family: "ff-tisa-web-pro-1", "ff-tisa-web-pro-2", "Lucida Grande", "Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", "Hiragino Sans GB W3", "WenQuanYi Micro Hei", sans-serif;
        }

        h1, .h1, h2, .h2, h3, .h3, h4, .h4, .lead {
            font-family: "ff-tisa-web-pro-1", "ff-tisa-web-pro-2", "Lucida Grande", "Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", "Hiragino Sans GB W3", "Microsoft YaHei UI", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
        }

        /*pre code {*/
        /*background: transparent;*/
        /*}*/

        @media (min-width: 768px) {
            .bs-docs-home .bs-social,
            .bs-docs-home .bs-masthead-links {
                margin-left: 0;
            }
        }

        .bs-docs-section p {
            line-height: 2;
        }

        .bs-docs-section p.lead {
            line-height: 1.4;
        }

        div#alertModal.modal.fade.bs-example-modal-sm.in {
            overflow: hidden;
        }

        .wide-modal{
            width: 800px;
        }

    </style>

    <!--[if lt IE 9]>
    <script src="dist/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="dist/js/html5shiv.min.js"></script>
    <script src="dist/js/respond.min.js"></script>
    <![endif]-->

    <!-- Favicons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="dist/images/apple-touch-icon-144-precomposed.png">
    <link rel="shortcut icon" href="dist/images/favicon.png">
    <link rel="stylesheet" href="/stylesheets/style.css">


</head>
<body>
<a class="sr-only" href="#content">Skip to main content</a>

<!-- Docs master nav -->
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="#" class="navbar-brand">美人黛接口</a>
        </div>
        <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
            <ul class="nav navbar-nav">
                <%
                    apps.forEach(function(app){
                %>
                <li class="pt-<%=app.pathName%>">
                    <a href="/view-<%=app.pathName%>"><%=app.name%></a>
                </li>
                <%
                    });
                %>

                <!--<li class="pt-appInterface-0410">-->
                    <!--<a href="/view-appInterface-0410">Version4.1</a>-->
                <!--</li>-->
                <!--<li class="pt-appInterface-0420">-->
                    <!--<a href="/view-appInterface-0420">Version4.2</a>-->
                <!--</li>-->
                <!--<li class="pt-armyInterface">-->
                    <!--<a href="/view-armyInterface">军工项目</a>-->
                <!--</li>-->
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#" id="toJspDev">JSP调试</a></li>
                <li class="hide" style="cursor:pointer;">
                        <a class="doc-drop-down-menu" data-toggle="dropdown">
                            美黛产品文档
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" target="_blank" href="/mrd_doc/mrd-prdt-wechat/start.html">美人黛微信端2.0</a>
                            </li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" target="_blank" href="/mrd_doc/mrd-yw-web/start.html">美人黛业务端2.0</a>
                            </li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" target="_blank" href="/mrd_doc/mrd-wechat-outline/start.html">美人黛微信线框图2.2</a>
                            </li>
                        </ul>

                </li>
                <li>
                    <a id="toManage" href="#">接口管理</a>
                </li>
            </ul>
        </nav>
    </div>
</header>

<!-- Docs page layout -->
<div class="bs-header" id="content">
    <div class="container">
        <h1>概述</h1>

        <p>所有api均为http请求，get请求参数为QueryString格式，post请求体为json格式，Content-Type为application/json; charset=UTF-8</p>

    </div>
</div>

<div id="moduleTestInterface" class="modal fade bs-example-modal-sm " tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm wide-modal">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">接口调试</h4>
            </div>
            <div class="modal-body">
                <form id="moduleForm">
                    <div class="form-group">
                        <label for="mCode">接口URL</label>
                        <div class="input-group">
                            <div class="input-group-addon">http://</div>
                            <input class="form-control" id="tHost" type="text" placeholder="填写IP与端口">
                            <div class="input-group-addon" id="tUrlPath"></div>
                        </div>

                    </div>
                    <div class="form-group">
                        <label for="mName">请求参数</label>
                        <textarea class="form-control" rows="5" id="tParamJSON"></textarea>
                        <table class="table table-striped" id="tParamForm">
                            <thead>
                            <tr>
                                <th scope="col" class="col-xs-3">参数名称</th>
                                <th scope="col" class="col-xs-7">参数描述</th>
                                <th scope="col" class="col-xs-2">操作</th>
                            </tr>
                            </thead>
                            <tbody id="iTableParam">
                            <tr class="param-first-row">
                                <td><input class="form-control input-sm param-name" type="text"
                                           placeholder="参数名称"></td>
                                <td><input class="form-control input-sm param-desc" type="text"
                                           placeholder="参数描述"></td>
                                <td align="center">
                                    <button type="button" class="btn btn-success btn-sm param-btn-add">
                                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                                    </button>
                                </td>
                            </tr>

                            </tbody>
                        </table>
                    </div>
                    <div class="form-group">
                        <label for="mOrder">返回结果</label>
                        <div id="tNotice" class="alert alert-warning" role="alert">请求中，请稍候...</div>
                        <pre id="tResult"><code class="json"></code></pre>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btnDoTestInterface" type="button" class="btn btn-primary">测试</button>
            </div>

        </div>
    </div>
</div>

<!-- Callout for the old docs link -->


<div class="container bs-docs-container">
    <div class="row">
        <div class="col-md-3">
            <div class="bs-sidebar hidden-print" role="complementary">
                <ul class="nav bs-sidenav">
                    <% var mIndex = 0, iIndex = 0;%>
                    <% list.forEach(function(mObj){%>
                    <li>
                        <a href="#<%=mObj.interfaceId%>"><%=++mIndex%>&nbsp; <%=mObj.name%></a>
                        <%if(mObj.ifs && mObj.ifs.length){ iIndex = 0;%>
                        <ul class="nav">
                            <%mObj.ifs.forEach(function(ifObj){ %>
                            <li><a href="#<%=ifObj.interfaceId%>"><%=mIndex%>.<%=++iIndex%>&nbsp; <%=ifObj.name%></a></li>
                            <%})%>
                        </ul>
                        <%}%>
                    </li>
                    <%})%>
                </ul>
            </div>
        </div>
        <div class="col-md-9" role="main">
            <%  mIndex = 0; %>
            <% list.forEach(function(mObj){%>
            <!-- <%=mObj.name%>
            ================================================== -->
            <div class="bs-docs-section">
                <div class="page-header">
                    <h1 id="<%=mObj.interfaceId%>"><%=++mIndex%>&nbsp; <%=mObj.name%></h1>
                </div>
                <p class="lead"><%=mObj.name%>相关接口</p>


                <%if(mObj.ifs && mObj.ifs.length){ iIndex = 0;%>
                <%mObj.ifs.forEach(function(ifObj){%>
                <!-- 创建对象 -->
                <h2 id="<%=ifObj.interfaceId%>">&nbsp;</h2>
                <h3 >
                    <%=mIndex%>.<%=++iIndex%>&nbsp; <%=ifObj.name%> <%=ifObj.detailInfo.author ? '- （Author：' + ifObj.detailInfo.author + '）'  :''%>
                    <%=ifObj.detailInfo.ifType === 'jsp' ? '【 JSP页面 】' : ''%>
                </h3>
                <% if(ifObj.detailInfo.ifType === 'jsp'){%>
                <p>若要调试本页面，请打开tomcat服务，并使用<a href="javascript: void(0);">JSP调试</a>功能进行调试。 <br>
                    页面资源路径： <code><%=ifObj.detailInfo.resultPage%></code></p>
                <%}else{%>
                <p><%-ifObj.detailInfo.desc || '（无对应描述）'%></p>
                <%}%>
                <!--<p>文档中所有api的url，都需要租户代码。当未选择租户时，请使用 <code>default</code>作为租户代码</p>-->
                <p></p>
                <br/>
                <h4>请求URL</h4>
                <% if(ifObj.detailInfo.ifType === 'jsp'){%>
                <pre>/<%=ifObj.detailInfo.url.charAt(0) === '/' ? ifObj.detailInfo.url.substring(1) : ifObj.detailInfo.url%></pre>
                <%}else{%>
                <pre>http://minidoc.meirendai.com.cn/api-<%=appName%>/<%=ifObj.detailInfo.url.charAt(0) === '/' ? ifObj.detailInfo.url.substring(1) : ifObj.detailInfo.url%></pre>
                <%}%>

                <% if(ifObj.detailInfo.ifType !== 'jsp'){%>
                <button type="button" class="btn btn-primary cmd-test-btn" data-ifid="<%=ifObj.detailInfo.interfaceId%>">远程调试接口</button>
                <p></p>
                <br/>
                <%
                   var paramType = ifObj.detailInfo.paramType, pArray = ifObj.detailInfo.params, paramDemo;
                   if(paramType){
                       paramDemo = pArray.shift();
                %>
                <h4>请求体示例</h4>
                <pre><code class="json"><%=paramDemo%></code></pre>
                <br>
                <%
                   }
                %>
                <h4><%=paramType ? '请求体属性' : '请求参数'%></h4>
                <%
                 var i = 0;
                    if(pArray && pArray.length){
                  %>
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th scope="col" class="col-xs-2">#</th>
                        <th scope="col" class="col-xs-3"><%=paramType ? '属性名称' : '参数名称'%></th>
                        <th scope="col" class="col-xs-7"><%=paramType ? '属性描述' : '参数描述'%></th>
                    </tr>
                    </thead>
                    <tbody>
                    <%pArray.forEach(function(pInfo){
                        pInfo = pInfo.split('|');
                    %>
                    <tr>
                        <th scope="row"><%=++i%></th>
                        <td><%-pInfo[0]%></td>
                        <td><%-pInfo[1]%></td>
                    </tr>
                    <%})%>
                    </tbody>
                </table>

                <%}else{%>
                <p>（无）</p>
                <%}%>
                <%}%>
                <h4><%=ifObj.detailInfo.ifType === 'jsp' ? '页面数据示例' : '返回结果示例'%></h4>
                <pre>
<code class="json"><%=ifObj.detailInfo.resultDemo%></code></pre>
                <br/>

                <h4><%=ifObj.detailInfo.ifType === 'jsp' ? '页面数据属性' : '返回结果属性'%>返回结果属性</h4>

                <%
                    var aArray = ifObj.detailInfo.attrInfos, j = 0;
                if(aArray && aArray.length){
                %>
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th scope="col" class="col-xs-2">#</th>
                        <th scope="col" class="col-xs-3">参数名称</th>
                        <th scope="col" class="col-xs-7">参数描述</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%aArray.forEach(function(aInfo){
                        aInfo = aInfo.split('|');
                    %>
                    <tr>
                        <th scope="row"><%=++j%></th>
                        <td><%-aInfo[0]%></td>
                        <td><%-aInfo[1]%></td>
                    </tr>
                    <%})%>
                    </tbody>
                </table>

                <%}else{%>
                <p>（无）</p>
                <%}%>
                <h4></h4>
                <br/>
                <%})%>
                <h4></h4>
                <br/>
                <%}%>
            </div>


            <%})%>
        </div>
    </div>
</div>
<!-- Footer
================================================== -->
<footer class="bs-footer" role="contentinfo">
    <div class="container">

        <p>开发接口文档 &nbsp;&nbsp;&nbsp;&nbsp;<em>Author : xinxinran</em></p>

    </div>
</footer>

<!-- JS and analytics only. -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../dist/js/jquery.min.js"></script>


<script src="../dist/js/bootstrap.js"></script>

<script src="../dist/js/holder.min.js"></script>
<script src="../dist/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<script src="../dist/js/application.js"></script>

<script type="text/javascript">
    window.fakeStorage = {
        _data: {},

        setItem: function (id, val) {
            return this._data[id] = String(val);
        },

        getItem: function (id) {
            return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
        },

        removeItem: function (id) {
            return delete this._data[id];
        },

        clear: function () {
            return this._data = {};
        }
    };

    function LocalStoreManager() {
        var localSupported = !!window.localStorage;
        this.storage = localSupported ? window.localStorage : window.fakeStorage;
    }

    LocalStoreManager.prototype.get = function (key) {
        var result = this.storage.getItem(key);
        if (result && result.charAt(0) === 's') {
            return result.substring(2);
        } else if (result && result.charAt(0) === 'o') {
            try {
                return JSON.parse(result.substring(2));
            } catch (ignore) {
            }
        }
        return null;
    };

    LocalStoreManager.prototype.set = function (key, content) {
        if (typeof content === 'string') {
            content = 's:' + content;
        } else if (typeof content === 'object' && content) {
            content = 'o:' + JSON.stringify(content);
        } else {
            content = null;
        }

        content && this.storage.setItem(key, content);
    };

    LocalStoreManager.prototype.remove = function (key) {

        this.storage.removeItem(key);
    };

</script>

<script type="text/javascript">

    (function ($) {
        var initDeferred = new $.Deferred(), mainPromise = initDeferred.promise(), $alert = $('#alertModal'),
                $alertTxt = $('#alertModalTxt'), $alertVal = $('#alertModalValue'), pathVarRegx = /\/view-([^/]+)\/?/,

                thisURL = window.location.pathname, pathInfo = pathVarRegx.exec(thisURL), appName = pathInfo[1],
            ptRowTpl = '<tr class="pt-added" data-extra-flag="#{extraFlag}">' +
                '<td>#{paramName}</td>' +
                '<td><input class="form-control input-sm param-desc" type="text" placeholder="参数值" value="#{paramValue}" data-param-name="#{paramName}"></td>' +
                '<td align="center">' +
                '<div class="btn-group" role="group" aria-label="...">' +
                '<button type="button" class="btn btn-success btn-sm param-btn-add">' +
                '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>' +
                '</button>' +
                '<button type="button" class="btn btn-warning btn-sm param-btn-del #{hideFlag}">' +
                '<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>' +
                '</button>' +
                '</div>' +
                '</td>' +
                '</tr>',
            $tNotice = $('#tNotice'), $moduleTestInterface = $('#moduleTestInterface'), storeManager = new LocalStoreManager(),
            $tUrlPath = $('#tUrlPath'), $btnDoTestInterface = $('#btnDoTestInterface'), $tParamJSON = $('#tParamJSON'),
            $tParamForm = $('#tParamForm'), $iTableParam = $('#iTableParam'), $tHost = $('#tHost'), $tResult = $('#tResult'), ifCache = {};

        $('.pt-' + appName).addClass('active');

        initDeferred.resolve();

        function addPtRow(paramName, paramValue, canDelete){
            paramName = paramName || '<input class="form-control input-sm param-name" type="text" placeholder="参数名">';
            $iTableParam.append(formatString(ptRowTpl, {paramName: paramName, paramValue: paramValue || '',
                hideFlag : (canDelete ? '' : 'hide'), extraFlag : (canDelete ? '1' : '0')}));
        }

        function formatString(txt, obj) {
            var arr = Array.prototype.slice.call(arguments, 1);
            return txt.replace(/\\?#\{([^{}]+)}/gm, function (match, name) {
                if (match.charAt(0) === '\\') {
                    return match.slice(1);
                }
                var index = Number(name);
                if (index >= 0) {
                    return arr[index];
                }
                if (obj && obj[name] !== void 0) {
                    return obj[name];
                }
                return '';
            });
        }

        $.myAlert = function (txt, value, err) {
            mainPromise = mainPromise.then(function () {
                var newDeferred = new $.Deferred();
                $alertTxt.text(txt);
                $alertVal.text(err ? '发生错误——' + err : String(value));
                $alert.data('myDeferred', newDeferred).modal();
                return newDeferred.promise();
            });
        };

        $alert.on('hidden.bs.modal', function () {
            $alert.data('myDeferred').resolve();
        });

        $('.cmd-test-btn').click(function(){
            var $this = $(this), ifId = $this.data('ifid');

            if(ifCache[ifId]){
                initTestModal(ifCache[ifId]);
            }else{
                $.getJSON('/view-' + appName + '/getIf/' + ifId).done(function(ifObj){
                    ifCache[ifId] = ifObj.result;
                    initTestModal(ifObj.result);
                });
            }


        });

        function initTestModal(ifObj){
            var ifDetail = ifObj.detailInfo, ifId = ifDetail.interfaceId,
                cacheParams = storeManager.get('tif-params-' + ifId), cacheParamContent;
            $tUrlPath.text(ifDetail.url);
            $tHost.val(storeManager.get('tif-host') || '').data('url', ifDetail.url);
            $iTableParam.empty();
            if(!ifDetail.paramType){
                $tParamJSON.addClass('hide');
                $tParamForm.removeClass('hide');

                cacheParamContent = cacheParams ? cacheParams.content[0] : {};

                ifDetail.params && ifDetail.params.forEach(function(v){
                    var pInfo = v.split('|'), pName = pInfo[0];
                    addPtRow(pName, cacheParamContent[pName] || '');
                });
            }else {
                $tParamJSON.removeClass('hide');
                $tParamForm.addClass('hide');

                $tParamJSON.val(cacheParams ? cacheParams.content : ifDetail.params.shift());
            }

            $btnDoTestInterface.data('ifId', ifId).data('paramType', ifDetail.paramType);

            doNotice('填写完整后请点击测试按钮。', 'info');
            $tResult.addClass('hide');
            $moduleTestInterface.modal();


        }

        $btnDoTestInterface.click(function(){
            var tHost = $tHost.val(), params, tmpJsonContent,
                $this = $(this), paramType = $this.data('paramType'), ifId = $this.data('ifId'),
                cacheContent ;
            if(!tHost) {
                doNotice('请填写服务器IP地址', 'warning');
                return;
            }

            if(paramType){
                params = $tParamJSON.val();
                if(!(tmpJsonContent = checkJSON(params))){
                    doNotice('请填写正确的JSON格式', 'warning');
                    return;
                }else{
                    tmpJsonContent = JSON.stringify(tmpJsonContent);
                }
                cacheContent = params;
                params = [tmpJsonContent];

            }else{
                params = [];
                cacheContent = {};
                $iTableParam.find('tr').each(function(){
                    var $thisTr = $(this), trFlag = +$thisTr.data('extraFlag'), targetInput, tmpName;
                    if(!trFlag){
                        targetInput = $thisTr.find('.param-desc');
                        params.push(targetInput.data('paramName'), targetInput.val());
                        cacheContent[targetInput.data('paramName')] = targetInput.val();
                    }else{
                        targetInput = $thisTr.find('.param-name');
                        params.push(tmpName = targetInput.val());
                        targetInput = $thisTr.find('.param-desc');
                        params.push(targetInput.val());
                        cacheContent[tmpName] = targetInput.val();
                    }
                });
            }

            storeManager.set('tif-host', tHost);
            storeManager.set('tif-params-' + ifId, {content : cacheContent, ts : +new Date()});

            doNotice('后台请求中...', 'info');

            $.post('/helper/testIf', {
                host: tHost,
                path: $tHost.data('url'),
                params: params,
                paramType: paramType
            }, null, 'json')
                .done(function (jsonResult) {
                    doNotice();
                    $tResult.removeClass('hide').find('code').text(JSON.stringify(jsonResult, null, 4));
                    hljs.highlightBlock($tResult[0]);
                }).fail(function(err){
                doNotice('请求错误 ： ' + err, 'danger');
            });
        });

        function checkJSON(demoContent){
            var demoObj;
            try {
                demoContent.replace(/[“”]/g, '"');
                demoObj = JSON.parse(demoContent);
            } catch (e) {
                try {
                    demoObj = (new Function('return ' + demoContent))();
                } catch (e) {
                    demoObj = null;
                }

            }

            return demoObj;
        }

        var levelHeaders = {info : '信息 ', warning : '提示 ', danger : '错误 '}
        function doNotice(txt, level, header){
            if(level){
                header = header || levelHeaders[level];
                $tNotice.removeClass().addClass('alert').addClass('alert-' + level);
                $tNotice.html(formatString('<strong>#{0}</strong> #{1}', header, txt));
            }else{
                $tNotice.addClass('hide');
            }

        }

        $('#toManage').click(function(){
            window.location.href = '/manage-' + appName;
        });

        $('#toJspDev').on('click', function(){
            window.open('/jspdev-' + appName);
        });
    })(jQuery);

</script>
</body>
</html>
